<?php

/**
 * Require PHPUnit_Framework_TestSuite
 */
require_once 'PHPUnit/Framework/TestSuite.php';

/**
 * The base test suite class for all PDODB test suites.
 *
 * @package     PDODB
 * @category    Database
 * @author      Michael J. I. Jackson <mjijackson@gmail.com>
 */
class PDODB_TestSuite extends PHPUnit_Framework_TestSuite
{

    /**
     * Stores the database connection parameters needed for this test suite
     * in its $sharedFixture variable.
     *
     * @return  void
     * @access  protected
     */
    protected function setUp()
    {
        preg_match('/PDODB_(\w+)/', $this->getName(), $match);
        $driver = $match[1];

        if (!isset($GLOBALS['PDODB_TEST'][$driver])) {
            $this->markTestSuiteSkipped('No connection parameters defined for driver ' . $name);
            return;
        }

        $dsn = null;
        if (!empty($GLOBALS['PDODB_TEST'][$driver]['dsn'])) {
            $dsn = $GLOBALS['PDODB_TEST'][$driver]['dsn'];
        }

        $user = null;
        if (!empty($GLOBALS['PDODB_TEST'][$driver]['user'])) {
            $user = $GLOBALS['PDODB_TEST'][$driver]['user'];
        }

        $pass = null;
        if (!empty($GLOBALS['PDODB_TEST'][$driver]['pass'])) {
            $pass = $GLOBALS['PDODB_TEST'][$driver]['pass'];
        }

        $this->sharedFixture = array(
            'driver'    => $driver,
            'dsn'       => $dsn,
            'user'      => $user,
            'pass'      => $pass
        );
    }

}

/**
 * Require database connection parameters
 */
if (is_readable('conf.php')) {
    require_once 'conf.php';
} else {
    require_once 'conf.php.dist';
}

?>
